﻿using BootstrapBlazor.Components;
using JinShun.OA.UI.Dtos.Navigation;
using JinShun.OA.UI.Extensions;
using JinShun.OA.UI.IServer.Navigation;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Routing;

namespace JinShun.OA.UI.Components.Shared
{
    /// <summary>
    /// 
    /// </summary>
    public sealed partial class MainLayout
    {
        private bool UseTabSet { get; set; } = true;

        private string Theme { get; set; } = "";

        private bool IsOpen { get; set; }

        private bool IsFixedHeader { get; set; } = true;

        private bool IsFixedFooter { get; set; } = true;

        private bool IsFullSide { get; set; } = true;

        private bool ShowFooter { get; set; } = true;

        private List<MenuItem>? Menus { get; set; }
        [Inject] public AuthenticationStateProvider AuthenticationStateProvider { get; set; }
        [Inject] private INavigation? NavigationsService { get; set; }

        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();
        }

        //private static List<MenuItem> GetIconSideMenuItems()
        //{
        //    var menus = new List<MenuItem>
        //    {
        //        new() { Text = "首页", Icon = "fa-solid fa-fw fa-flag", Url = "/" , Match = NavLinkMatch.All},
        //        new() { Text = "卡片管理", Icon = "fa-solid fa-fw fa-check-square", Url = "/counter" },
        //        new() { Text = "套餐管理", Icon = "fa-solid fa-fw fa-database", Url = "/weather" },
        //        new() { Text = "订单列表", Icon = "fa-solid fa-fw fa-table", Url = "/table" },
        //        new() { Text = "财务管理", Icon = "fa-solid fa-fw fa-users", Url = "/users" },
        //        new() { Text = "统计报表", Icon = "fa-solid fa-fw fa-users", Url = "/users" }
        //    };

        //    return menus;
        //}

        /// <summary>
        /// OnInitializedAsync 方法
        /// </summary>
        /// <returns></returns>
        protected override async Task OnInitializedAsync()
        {
            var authenticationState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
            var User = authenticationState.User;
            if (User != null && User.Claims.Count() > 0)
            {
                List<NavigationOutDto> list = await NavigationsService.GetAllMenusAsync();
                Menus = await MenuExtensions.ToMenus(list);
            }
        }
    }
}
